//
//  EnvelopeAnimationViewController.m
//  Text_ problem
//
//  Created by jiboxue on 13-1-22.
//  Copyright (c) 2013年 jiboxue. All rights reserved.
//

#import "EnvelopeAnimationViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "PMAPI.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "json.h"
#import "CustomerInformation.h"


@interface EnvelopeAnimationViewController ()

@end

@implementation EnvelopeAnimationViewController

@synthesize stars = _stars;
@synthesize stars1 = _stars1;

@synthesize button_confirm = _button_confirm;

@synthesize isQuestion1Answered;
@synthesize isQuestion2Answered;

@synthesize label_seal_china = _label_seal_china;
@synthesize label_seal_english = _label_seal_english;


static int i = 49;
static int j = 172;
static int k = 95;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//开始信封出来的动画定时器
-(void)timer{
    
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    self.imageView_boby.alpha = 0;
    [self.logo_one_animation3 invalidate];
    self.logo_one_animation3 = nil;
    k = 95;
    [self.Button_herein_animation invalidate];
    self.Button_herein_animation = nil;
    j = 172;
    [self.logo_one_animation invalidate];
    self.logo_one_animation = nil;
    i = 49;
    self.logo_one_animation = [NSTimer scheduledTimerWithTimeInterval:4.0/66.0 target:self selector:@selector(logo_one_animation:) userInfo:nil repeats:YES];
    NSLog(@"111111111111111111111 %@", self.logo_one_animation);
}
-(void)playSound:(NSString*)soundKey{
	
	NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath],soundKey];
	SystemSoundID soundID;
	NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
	AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
	AudioServicesPlaySystemSound(soundID);
}
-(void)playavadio:(NSString *)avadio
{
    NSString *mp3Path = [[NSBundle mainBundle]pathForResource:avadio ofType:@"mp3"];
    if ([[NSFileManager defaultManager]fileExistsAtPath:mp3Path])
    {
        NSURL *mp3URL = [[[NSURL alloc]initFileURLWithPath:mp3Path]autorelease];
        NSError *error=nil;
        self.audioPlayer = [[[AVAudioPlayer alloc]initWithContentsOfURL:mp3URL error:&error]autorelease];
        if (error != nil)
        {
            NSLog(@"error:%@",error);
        }
        else
        {
            self.audioPlayer.volume = 0.5;
            self.audioPlayer.numberOfLoops = 0;//循环播放,默认0,不循环
            [self.audioPlayer prepareToPlay];//准备波饭,缓冲数据
            self.audioPlayer.delegate = self;
            [self.audioPlayer play];
        }
    }
}
-(void)setup
{
    self.imageView_message = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
    self.imageView_boby = [[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
    _stars = [[NSMutableArray alloc]init];
    _stars1 = [[NSMutableArray alloc]init];
    
    appD = [UIApplication sharedApplication].delegate;
    
    
    self.label_ask = [[[UILabel alloc]initWithFrame:CGRectMake(375, 240, 410, 70)]autorelease];
    self.label_answer = [[[UILabel alloc]initWithFrame:CGRectMake(375, 295, 65, 30)]autorelease];
    self.label_ask1 = [[[UILabel alloc]initWithFrame:CGRectMake(375, 460, 410, 70)]autorelease];
    self.label_answer1 = [[[UILabel alloc]initWithFrame:CGRectMake(375, 509, 65, 30)]autorelease];
    
    self.imageView_Headimage = [[[UIImageView alloc]initWithFrame:CGRectMake(515, 140, 96, 99)]autorelease];
    self.label_name_china = [[[UILabel alloc]initWithFrame:CGRectMake(640, 155, 100, 30)]autorelease];

}
-(void)back
{
    self.imageView_message.alpha = 0;
    self.imageView_boby.alpha = 0;
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    
    [self.logo_one_animation3 invalidate];
    self.logo_one_animation3 = nil;
    [self.Button_herein_animation invalidate];
    self.Button_herein_animation = nil;
    
    [self.logo_one_animation invalidate];
    self.logo_one_animation = nil;
    
    i = 49;
    j = 172;
    k = 95;
    [self setup];
    [self content];
    [self problems];
//    self.imageView_message.image = [UIImage imageNamed:@"letter_00049.png"];
//    self.imageView_message.alpha = 0;
    self.imageView_Headimage .alpha = 0;
    self.label_name_china.alpha = 0;
    self.label_name_english.alpha = 0;

    appD.rootVC.view_message.alpha = 0;
    appD.rootVC.EnvelopeAnimationVC.view.alpha = 0;

    appD.rootVC.view_white.alpha = 0;
    appD.rootVC.view_white.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    appD.rootVC.imageView_InScreen.alpha = 0;

  //***********************************************
    
    _label_seal_china.alpha = 0;
    _label_seal_english.alpha = 0;
    self.imageView_boby.alpha = 0;
    _button_confirm.alpha = 0;
    
    
    for ( UIButton* btnTemp in _stars) {
        btnTemp.alpha = 0;
    }
    for ( UIButton* btnTemp1 in _stars1) {
        btnTemp1.alpha = 0;
    }
    self.label_ask.alpha = 0;
    self.label_ask1.alpha = 0;
    self.label_answer.alpha = 0;
    self.label_answer1.alpha = 0;
    self.label_name_china.alpha = 0;
    self.label_name_english.alpha = 0;
    _underLine.alpha = 0;
    self.imageView_Headimage.alpha = 0;
//
    appD.rootVC.view_message.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
//
    appD.rootVC.view_message.alpha = 0;
    appD.rootVC.EnvelopeAnimationVC.view.alpha = 0;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self setup];
    [self content];
    [self problems];
}

-(void)content
{
    self.imageView_message.image = [UIImage imageNamed:@"letter_00049.png"];
    self.imageView_message.userInteractionEnabled = YES;
    
    [self.view addSubview:self.imageView_message];
    [self.view addSubview:self.imageView_boby];
    
    self.imageView_Headimage .image = [UIImage imageNamed:@"head.png"];
    self.imageView_Headimage.alpha = 0;
    [self.imageView_message addSubview:self.imageView_Headimage ];
    
    //名字
    self.label_name_china.alpha = 0;
    
    [self.imageView_message addSubview:self.label_name_china];
    
    self.label_name_english = [[[UILabel alloc]initWithFrame:CGRectMake(640, 178, 100,30)]autorelease];
    self.label_name_english.text = @"jiboxue";
    [self.label_name_english setFont:[UIFont fontWithName:@"ArialMT" size:20.0f]];
    //以下2句话时关键
    //[self.label_name_english sizeToFit];
    
    self.label_name_english.alpha = 0;
    [self.label_name_english setShadowOffset:CGSizeMake(0, -1)];
    [self.label_name_english setShadowColor:[UIColor whiteColor]];
    [self.label_name_english setBackgroundColor:[UIColor clearColor]];
    self.label_name_english.textColor = [UIColor brownColor];
    [self.imageView_message addSubview:self.label_name_english];
    
    //下划线视图
    self.underLine = [[[UIView alloc]init]autorelease];
    self.underLine.alpha = 0;
    self.underLine.backgroundColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1];
    //self.underLine.frame = CGRectMake(640, 147, 100, 30);
    //[self.imageView_message addSubview:self.underLine];

}

-(void)problems
{
    //问题
    self.label_ask.alpha = 0;
    [self.label_ask setNumberOfLines:2];
    [self.label_ask setShadowOffset:CGSizeMake(0, -1)];
    [self.label_ask setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [self.label_ask setBackgroundColor:[UIColor clearColor]];
    ///
    [self.label_ask setFont:[UIFont fontWithName:@"ArialMT" size:17.0f]];
    self.label_ask.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1.0];
    
    self.label_ask.adjustsFontSizeToFitWidth = YES;
    self.label_ask.minimumFontSize = 20;
    [self.imageView_message addSubview:self.label_ask];
    
    self.label_answer.alpha = 0;
    self.label_answer.text = @"Rating";
    self.label_answer.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1.0];
    [self.label_answer setShadowOffset:CGSizeMake(0, -1)];
    [self.label_answer setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [self.label_answer setBackgroundColor:[UIColor clearColor]];
    [self.label_answer setFont:[UIFont fontWithName:@"ArialMT" size:18.0f]];
    [self.imageView_message addSubview:self.label_answer];
    
    
    _button_confirm = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_button_confirm setBackgroundImage:[UIImage imageNamed:@"btn_normal.png"] forState:UIControlStateNormal];
    _button_confirm.alpha = 0;
    _button_confirm.frame = CGRectMake(500, 680, 118, 38);
    [_button_confirm addTarget:self action:@selector(button_confirm_cure) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView_message addSubview:_button_confirm];
    
    for (int i = 0; i < 7; i++)
    {
        UIButton* btnTemp = [UIButton buttonWithType:UIButtonTypeCustom];
        btnTemp.frame = CGRectMake((375 + i*60), 322, 40, 40);
        btnTemp.tag = 10 + i;
        btnTemp.alpha = 0;
        [btnTemp setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
        [btnTemp addTarget:self action:@selector(button1press:) forControlEvents:UIControlEventTouchUpInside];
        //UIControlEventTouchUpInside
        [self.imageView_message addSubview:btnTemp];
        [_stars addObject:btnTemp];/////////
    }
    
    //问题
    self.label_ask1.alpha = 0;
    [self.label_ask1 setNumberOfLines:2];
    [self.label_ask1 setShadowOffset:CGSizeMake(0, -1)];
    [self.label_ask1 setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [self.label_ask1 setBackgroundColor:[UIColor clearColor]];
    [self.label_ask1 setFont:[UIFont fontWithName:@"ArialMT" size:17.0f]];
    self.label_ask1.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1.0];
    self.label_ask1.adjustsFontSizeToFitWidth = YES;
    self.label_ask1.minimumFontSize = 20;
    [self.imageView_message addSubview:self.label_ask1];
    
    self.label_answer1.alpha = 0;
    self.label_answer1.text = @"Rating";
    self.label_answer1.textColor = [UIColor colorWithRed:160.0/255 green:160.0/255 blue:160.0/255 alpha:1];
    [self.label_answer1 setShadowOffset:CGSizeMake(0, -1)];
    [self.label_answer1 setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
    [self.label_answer1 setBackgroundColor:[UIColor clearColor]];
    [self.label_answer1 setFont:[UIFont fontWithName:@"ArialMT" size:18.0f]];
    [self.imageView_message addSubview:self.label_answer1];
    
    for (int i = 0; i < 7; i++)
    {
        UIButton* btnTemp1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btnTemp1.frame = CGRectMake((375 + i*60), 553, 40, 40);
        btnTemp1.tag = 10 + i;
        btnTemp1.alpha = 0;
        [btnTemp1 setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
        [btnTemp1 addTarget:self action:@selector(button2press:) forControlEvents:UIControlEventTouchUpInside];
        [self.imageView_message addSubview:btnTemp1];
        [_stars1 addObject:btnTemp1];/////////
    }
    //印章上的东西
    self.label_seal_china = [[UILabel alloc]init];
    CGPoint center = CGPointMake(723, 650);
    self.label_seal_china.transform =  CGAffineTransformMakeRotation(M_PI*(-46.0/360));
    self.label_seal_china.text = @"纪博学";
    self.label_seal_china.adjustsFontSizeToFitWidth = YES;
    self.label_seal_china.alpha = 0;
    self.label_seal_china.backgroundColor = [UIColor clearColor];
    self.label_seal_china.textColor = [UIColor colorWithRed:37.0/255 green:50.0/255 blue:120.0/255 alpha:1];
    [ self.label_seal_china setFont:[UIFont fontWithName:@"STHeiti-Light" size:20.0f]];
    [ self.label_seal_china sizeToFit];
    self.label_seal_china.center = center;
    [self.imageView_message addSubview: self.label_seal_china];
    
    self.label_seal_english = [[UILabel alloc]init];
    CGPoint center1 = CGPointMake(730, 680);
    self.label_seal_english.transform =  CGAffineTransformMakeRotation(M_PI*(-46.0/360));
    self.label_seal_english.text = @"asadasdff";
    self.label_seal_english.adjustsFontSizeToFitWidth = YES;
    self.label_seal_english.alpha = 0;
    self.label_seal_english.backgroundColor = [UIColor clearColor];
    self.label_seal_english.textColor = [UIColor colorWithRed:37.0/255 green:50.0/255 blue:120.0/255 alpha:1];
    [self.label_seal_english setFont:[UIFont fontWithName:@"ArialMT" size:20.0f]];
    [ self.label_seal_english sizeToFit];
    self.label_seal_english.center = center1;
    [self.imageView_message addSubview:self.label_seal_english];
}

//按星星的方法
-(void)button1press:(id)sender
{
    UIButton *button = (UIButton *)sender;
    
//    soundFile = [NSString stringWithFormat:@"/letter_shinebtn.mp3"];
    //[self playSound: soundFile];
    
    [self buttonDark];
    for (int i =0 ; i <= button.tag%10; i++) {
        NSLog(@"%d",i);
        UIButton *btn = [_stars objectAtIndex:i];
        [btn setBackgroundImage:[UIImage imageNamed:@"star_leave.png"] forState:UIControlStateNormal];
        
        self.string_stars_number = [NSString stringWithFormat:@"%d",i+1];
        NSLog(@"转换 = %@",self.string_stars_number);
        
    }
    
    [self playavadio:[NSString stringWithFormat:@"/letter_shinebtn"]];
    
    isQuestion2Answered = YES;
    if (isQuestion1Answered) {
        [_button_confirm setBackgroundImage:[UIImage imageNamed:@"btn_pass.png"] forState:UIControlStateNormal];
    }
    self.label_answer.textColor = [UIColor colorWithRed:0 green:102.0/255 blue:173.0/255 alpha:1];
    [self.label_answer setShadowOffset:CGSizeMake(0, -1)];
    [self.label_answer setShadowColor:[UIColor whiteColor]];
}
-(void)buttonDark{
    for (UIButton* btn in _stars) {
        [btn setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
    }
}

//按星星的方法
-(void)button2press:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    [self button1Dark];
    for (int i =0 ; i <= btn.tag%10; i++) {
        NSLog(@"%d",i);
        UIButton *btn = [_stars1 objectAtIndex:i];
        [btn setBackgroundImage:[UIImage imageNamed:@"star_leave.png"] forState:UIControlStateNormal];
        
        self.string_stars1_number = [NSString stringWithFormat:@"%d",i+1];
        NSLog(@"转换1 = %@",self.string_stars1_number);
        
    }

    [self playavadio:[NSString stringWithFormat:@"/letter_shinebtn"]];
    
    isQuestion1Answered = YES;
    if (isQuestion2Answered) {
        [_button_confirm setBackgroundImage:[UIImage imageNamed:@"btn_pass.png"] forState:UIControlStateNormal];
    }
    self.label_answer1.textColor = [UIColor colorWithRed:0 green:102.0/255 blue:173.0/255 alpha:1];
    [self.label_answer1 setShadowOffset:CGSizeMake(0, -1)];
    [self.label_answer1 setShadowColor:[UIColor whiteColor]];
}
-(void)button1Dark{
    for (UIButton* btn in _stars1) {
        [btn setBackgroundImage:[UIImage imageNamed:@"star_normal.png"] forState:UIControlStateNormal];
    }
}
//信封里面文字按钮出来的方法
-(void)Text_display
{
    NSLog(@"2");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5f];
    for ( UIButton* btnTemp in _stars) {
        btnTemp.alpha = 1;
    }
    for ( UIButton* btnTemp1 in _stars1) {
        btnTemp1.alpha = 1;
    }
    self.label_ask.alpha = 1;
    self.label_ask1.alpha = 1;
    self.label_answer.alpha = 1;
    self.label_answer1.alpha = 1;
    self.label_name_china.alpha = 1;
    self.label_name_english.alpha = 1;
    self.underLine.alpha = 1;
    self.imageView_Headimage .alpha = 1;
    _button_confirm.alpha = 1;
    [UIView commitAnimations];
}
//信封飘出动画
-(void)logo_one_animation:(NSTimer *)timer
{
    NSLog(@"信封飘出 %@", timer);
    self.imageView_message.alpha = 1;
    if (i == 96) {
        [self.logo_one_animation invalidate];
        [self Text_display];
        i = 49;
        return;
    }
    
    NSString *imageName = [NSString stringWithFormat:@"letter_00%03d", i++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName
                 ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    self.imageView_message.image = imageData;
    
    [imageData release];
}
//点击完按钮之后的方法
-(void)button_confirm_cure
{
    if (isQuestion1Answered == YES && isQuestion2Answered == YES)
    {
        [self.audioPlayer stop];
        
        soundFile = [NSString stringWithFormat:@"/btn_big.mp3"];
        [self playSound: soundFile];
        ////////////////////////////////////////////////////
        NSDictionary *dictionaryUserInfo = [CustomerInformation userMessage];
        NSString *username1 = [dictionaryUserInfo objectForKey:@"username"];
        NSLog(@"111111111111111111 = %@",username1);
        NSString *password1 = [dictionaryUserInfo objectForKey:@"password"];
        NSLog(@"111111111111111111 = %@",password1);
        //先判断网络
        ASIHTTPRequest *request_latest = [PMAPI requestlatestUsernsme:username1 andPassword:password1];
        [request_latest startSynchronous];
        
        NSError *error = [request_latest error];
        if (error) {
            //todo something network error
            return [self showInfo:@"Internet Failure"];
            return;
        }
        
        if ([request_latest responseStatusCode] != 200)
        {
            return [self showInfo:@"user name and password do not match"];
            //todo something error with service error
        }
        
        self.button_confirm.userInteractionEnabled = NO;
        
        /////////////////////////////
        self.viewLanding = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)]autorelease];
        UILabel *label_login = [[[UILabel alloc]initWithFrame:CGRectMake(470, 390, 150, 50)]autorelease];
        label_login.text = @"Submit";
        label_login.textColor = [UIColor whiteColor];
        label_login.backgroundColor = [UIColor clearColor];
        [self.viewLanding addSubview:label_login];
        
        self.viewLanding.backgroundColor = [UIColor blackColor];
        self.viewLanding.alpha = 0.6;
        //加载完成后用
        self.viewLanding.tag = 101;
        //加载小火轮
        self.activity = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]autorelease];
        self.activity.frame = CGRectMake(0, 0, 30, 30);
        self.activity.center = self.viewLanding.center;
        [self.activity startAnimating];
        //加到页面上
        [self.viewLanding addSubview:self.activity];
        [self.view addSubview:self.viewLanding];
        
        ASIFormDataRequest *request_answer = [PMAPI requestUsername:username1 andPassword:password1 andQuestion:self.question_anwer1 andQuestion:self.question_anwer2 andAnswer_1:self.string_stars_number andAnswer_2:self.string_stars1_number];
        
        request_answer.delegate =self;
        [request_answer startSynchronous];
        
//        //消失
        [[self.view viewWithTag:101] removeFromSuperview];
        
        soundFile = [NSString stringWithFormat:@"/character_stamp.mp3"];
        [self playSound: soundFile];
        
        NSDictionary *dictionary_answer = [[request_answer responseString] JSONValue];
        NSLog(@"得到的分数 ＝ %@",dictionary_answer);
        
        appD.rootVC.label_InScreen_name.text = [[CustomerInformation userMessage] objectForKey:@"realname"];
        
        NSNumber *x = [dictionary_answer objectForKey:@"scroe"];
        NSLog(@"有的值 = %@",[dictionary_answer objectForKey:@"scroe"]);
        NSLog(@"有的值 = %@",x);
        if (x != nil)
        {
            NSString *str_score = [NSString stringWithFormat:@"%@",x];
            appD.rootVC.label_inScreen_score.text = str_score;
        }
        else
        {
            NSString *str_score = @"0";
            appD.rootVC.label_inScreen_score.text = str_score;
        }
        NSNumber *y = [dictionary_answer objectForKey:@"time"];
        NSString *str_time = [NSString stringWithFormat:@"%@",y];
        appD.rootVC.label_inScreen_hour.text = str_time;
        
               NSString *str_name = [dictionary_answer objectForKey:@"name"];
        NSLog(@"mingzi = %@",str_name);
        
        self.Button_herein_animation = [NSTimer scheduledTimerWithTimeInterval:2.5/45.0 target:self selector:@selector(Button_herein_animation:) userInfo:nil repeats:YES];

        [self performSelector:@selector(labelSealDisplay) withObject:nil afterDelay:2];
    }
    else
    {
        [self showInfo:@"Please rate all questions"];
    }
}
-(void)showInfo:(NSString *)textMessage
{
    UIAlertView *alertView =
    [[UIAlertView alloc] initWithTitle:@"Alert"
                               message:textMessage
                              delegate:self
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    
    [alertView show];
    [alertView release];
}
-(void)labelSealDisplay
{
    _label_seal_china.alpha = 1;
    _label_seal_english.alpha = 1;
}
//小人出来扣绰动画
-(void)Button_herein_animation:(NSTimer *)timer
{
    NSLog(@"小人出来扣绰");
    self.imageView_boby.alpha = 1;
    if (j == 218) {
        [self.Button_herein_animation invalidate];
        j = 172;
        [self performSelector:@selector(Seal_disappear_anmiation) withObject:nil afterDelay:1];
        return;
    }
    NSString *imageName = [NSString stringWithFormat:@"body_00%03d", j++];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName
                                                         ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    self.imageView_boby.image = imageData;
    
    [imageData release];
}
//按钮印章消失动画
-(void)Seal_disappear_anmiation
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3f];
    _label_seal_china.alpha = 0;
    _label_seal_english.alpha = 0;
    self.imageView_boby.alpha = 0;
    _button_confirm.alpha = 0;
    [UIView commitAnimations];

    [self performSelector:@selector(logo_end) withObject:nil afterDelay:0.5];
    
}
//新建里面东西消失动画
-(void)logo_end
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3f];
    for ( UIButton* btnTemp in _stars) {
        btnTemp.alpha = 0;
    }
    for ( UIButton* btnTemp1 in _stars1) {
        btnTemp1.alpha = 0;
    }
    self.label_ask.alpha = 0;
    self.label_ask1.alpha = 0;
    self.label_answer.alpha = 0;
    self.label_answer1.alpha = 0;
    self.label_name_china.alpha = 0;
    self.label_name_english.alpha = 0;
    self.underLine.alpha = 0;
    self.imageView_Headimage .alpha = 0;
    _button_confirm.alpha = 0;
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3.0f];
    appD.rootVC.view_message.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    [UIView commitAnimations];
    
    soundFile = [NSString stringWithFormat:@"/letter_close.mp3"];
	[self playSound: soundFile];
    //取消延迟方法
//    [NSObject cancelPreviousPerformRequestsWithTarget:self];

    [self performSelector:@selector(disappear) withObject:nil afterDelay:1.0];
    
    
    self.logo_one_animation3 = [NSTimer scheduledTimerWithTimeInterval:5.0/110.0 target:self selector:@selector(logo_one_animation3:) userInfo:nil repeats:YES];
    
}
-(void)disappear
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0f];
    
    self.imageView_message.alpha = 0;
    [UIView commitAnimations];

}
//信封收起动画
-(void)logo_one_animation3:(NSTimer *)timer
{
    if (k == 48) {
        [self.logo_one_animation3 invalidate];
        k = 95;
                
        [self performSelector:@selector(logo_one_4) withObject:nil afterDelay:0];
        return;
    }    
    NSString *imageName = [NSString stringWithFormat:@"letter_00%03d", k--];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName
                                                         ofType:@"png"];
    UIImage *imageData = [[UIImage alloc]initWithContentsOfFile:filePath];
    self.imageView_message.image = imageData;
    
    [imageData release];

}
-(void)logo_one_4
{
    appD.rootVC.imageView_image.alpha = 1;
    appD.rootVC.view_message.alpha = 0;
    appD.rootVC.EnvelopeAnimationVC.view.alpha = 0;
    
    appD.rootVC.view_white.alpha = 1;
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3.0f];
    appD.rootVC.view_white.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.65];
    [UIView commitAnimations];

    [self performSelector:@selector(InScreen) withObject:nil afterDelay:0.5];
}
-(void)InScreen
{
    soundFile = [NSString stringWithFormat:@"/show result.mp3"];
    [self playSound: soundFile];

    [UIView commitAnimations];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3.0f];
    appD.rootVC.imageView_InScreen.alpha = 1;
    [UIView commitAnimations];

    [self performSelector:@selector(AnViewWhite) withObject:nil afterDelay:6.0];
    
}
-(void)AnViewWhite
{
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5f];
    appD.rootVC.view_white.alpha = 0;
    appD.rootVC.view_white.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    appD.rootVC.imageView_InScreen.alpha = 0;
    [UIView commitAnimations];
    
    [self performSelector:@selector(messageAlpha) withObject:nil afterDelay:0];
    
}
-(void)messageAlpha
{
    [appD.rootVC timerinvalidate];
    
    [appD.rootVC.questionList removeLastObject];
    NSLog(@"appD.rootVC.questionList = %@",appD.rootVC.questionList);
    NSLog(@"appD.rootVC.questionList数量 = %d",appD.rootVC.questionList.count);
    if (appD.rootVC.questionList.count > 0)
    {
        [[NSNotificationCenter defaultCenter]postNotificationName:USERDEFAULT_WRITEOK object:nil];
    }

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(void)dealloc
{
    self.string_questionID_1 = nil;
    self.string_questionID_2 = nil;
    self.string_stars_number = nil;
    self.string_stars1_number = nil;
    self.audioPlayer = nil;
    self.imageView_Headimage = nil;
    [_stars release];
    [_stars1 release];
    self.imageView_boby = nil;

    [_button_confirm release];
    self.label_name_china = nil;
    self.label_name_english = nil;
    self.underLine = nil;
    self.label_ask = nil;
    self.label_ask1 = nil;
    self.label_answer = nil;
    self.label_answer1 = nil;
    [_label_seal_china release];
    [_label_seal_english release];
    
    [super dealloc];
}

- (void)stopTimers
{
    [self.logo_one_animation invalidate];
    self.logo_one_animation = nil;
    
    [self.logo_one_animation3 invalidate];
    self.logo_one_animation3 = nil;
    
    [self.Button_herein_animation invalidate];
    self.Button_herein_animation = nil;
}

@end
